// Copyright (c) 2002 Cunningham & Cunningham, Inc.
// Released under the terms of the GNU General Public License version 2 or later.

package com.fit4as.fit
{

import mx.formatters.DateFormatter;


public class TimedActionFixture extends ActionFixture {


    private static var dateFormatter : DateFormatter = createDateFormatter("hh:mm:ss");

    private static function createDateFormatter(format : String) : DateFormatter
    {
        var result : DateFormatter = new DateFormatter();
        result.formatString = format;
        return result;
    }

    // Traversal ////////////////////////////////

    override public function doTable(table : Parse) : void {
        super.doTable(table);
        table.parts.parts.last().more = td("time");
        table.parts.parts.last().more = td("split");
    }

    override public function doCells(cells : Parse) : void {
        var start : Date = time();
        super.doCells(cells);
        var split : Number = time().getTime() - start.getTime();

        cells.last().more = td(dateFormatter.format(start));
        cells.last().more = td(split < 1000 ? "&nbsp;" : ((split) / 1000.0).toString());
    }

    // Utility //////////////////////////////////

    public function time() : Date {
        return new Date();
    }

    public function td(body : String): Parse {
        return Parse.createParseFromStrings("td", info(body), null, null);
    }

}
}